package metrics;

import java.util.ArrayList;
import java.util.HashMap;

import summarizer.newversion.Summarizer;
import thesis.DataObject;
import thesis.Summary;

public class TimeEvaluate {
	public static boolean testSize = true;
	public static boolean testM = true;

	public static void evaluate(ArrayList<Summarizer> summarizers,
			HashMap<Long, DataObject> memoryTweets, int dimSize) {
		int repeat = 15;
		if (testSize) {
			int[] Ms = new int[] { 15, 30 };
			for (int k = 0; k < Ms.length; k++) {
				int M = Ms[k];
				System.out.println("----------M = " + M + " ---------------");
				int step = memoryTweets.size() / 10;
				for (int size = step; size <= memoryTweets.size(); size += step) {
					HashMap<Long, DataObject> tweetsCopy = new HashMap<Long, DataObject>();
					int count = 0;
					for (Long key : memoryTweets.keySet()) {
						tweetsCopy.put(key, memoryTweets.get(key));
						if (count++ == size) {
							break;
						}
					}
					double[] times = new double[summarizers.size()];
					for (int i = 0; i < summarizers.size(); i++) {
						double time = 0;
						for (int j = 0; j < repeat; j++) {
							summarizers.get(i).computeSummary(
									M,
									1,
									(HashMap<Long, DataObject>) tweetsCopy
											.clone(), dimSize);
							time += summarizers.get(i).getExecutionTime() / 1000.0;
						}
						times[i] = time / repeat;
					}
					System.out.print(size + "\t");
					for (int i = 0; i < summarizers.size(); i++) {
						System.out.printf("%.4f\t", times[i]);
					}
					System.out.print("\t");
					for (int i = 0; i < summarizers.size(); i++) {
						System.out.printf("%.4f\t", summarizers.get(i).opRatio);
					}
					System.out.println();
				}
			}
		}
		if (testM) {
			int[] sizes = new int[] { memoryTweets.size() / 3,
					memoryTweets.size() };
			for (int k = 0; k < sizes.length; k++) {
				int size = sizes[k];
				System.out.println("----------size = " + size
						+ " ---------------");
				for (int M = 10; M < 150; M += 10) {
					HashMap<Long, DataObject> tweetsCopy = new HashMap<Long, DataObject>();
					int count = 0;
					for (Long key : memoryTweets.keySet()) {
						tweetsCopy.put(key, memoryTweets.get(key));
						if (count++ == size) {
							break;
						}
					}
					double[] times = new double[summarizers.size()];
					for (int i = 0; i < summarizers.size(); i++) {
						double time = 0;
						for (int j = 0; j < repeat; j++) {
							summarizers.get(i).computeSummary(
									M,
									1,
									(HashMap<Long, DataObject>) tweetsCopy
											.clone(), dimSize);
							time += summarizers.get(i).getExecutionTime() / 1000.0;
						}
						times[i] = time / repeat;
					}
					System.out.print(M + "\t");
					for (int i = 0; i < summarizers.size(); i++) {
						System.out.printf("%.4f\t", times[i]);
					}
					System.out.print("\t");
					for (int i = 0; i < summarizers.size(); i++) {
						System.out.printf("%.4f\t", summarizers.get(i).opRatio);
					}
					System.out.println();
				}
			}
		}
	}
}
